﻿using System;
using System.Collections.Generic;
using System.Text;
using IBuy.DataAccessLayer;
using System.Data;
using System.Collections;
using System.Windows.Forms;

namespace IBuy.Entity
{
    public class DisCount
    {
        #region 私有成员
        private string agencyName;
        private string goodsName;
        private float discount;
        private IDatabase database;
        #endregion

        #region 公有属性
        /// <summary>
        /// 代理名称
        /// </summary>
        public string AgencyName
        {
            get { return agencyName; }
            set { agencyName = value; }
        }
        public string GoodsName
        {
            get { return goodsName; }
            set { goodsName = value; }
        }
        /// <summary>
        /// 折扣
        /// </summary>
        public float Discount
        {
            get { return discount; }
            set { discount = value; }
        }
        #endregion

        #region 公有方法
        public DisCount(string _agencyName)
        {
            AgencyName = _agencyName;
            DatabaseFactory databaseFactory = new OledbDatabaseFactory();
            database = databaseFactory.GetDatabase();
        }

        public DisCount()
        {
            AgencyName = "";
            DatabaseFactory databaseFactory = new OledbDatabaseFactory();
            database = databaseFactory.GetDatabase();
        }

        public DataSet GetDiscountByAgencyName(string _agencyName)
        {
            string SqlString = "select NAME,AGENCYNAME,DISCOUNT FROM DISCOUNTVIEW where AGENCYNAME='" + _agencyName + "'";
            return database.GetDataSet(SqlString);
        }

        public DataSet GetDiscountDataSetByName(string name)
        {
            string SqlString = "select NAME,AGENCYNAME,DISCOUNT FROM DISCOUNTVIEW where NAME='" + name + "'";
            return database.GetDataSet(SqlString);
        }

        public DataSet GetAllDiscountDataSet()
        {
            string SqlString = "select NAME,AGENCYNAME,DISCOUNT FROM DISCOUNTVIEW";
            return database.GetDataSet(SqlString);
        }

        public bool InsertAgencyDiscount(Hashtable cols)
        {
            //string sql = "Insert into DISCOUNT(AGENCYID,GOODSID,DISCOUNT) values(" + cols["AGENCYID"].ToString() + "," + cols["GOODSID"].ToString() + "," + cols["DISCOUNT"].ToString()+")";
            if (database.Insert("DISCOUNT",cols))
            {
                MessageBox.Show("添加代理商折扣信息成功！");
                return true;
            }
            else
            {
                MessageBox.Show("添加代理商折扣信息失败！");
                return false;
            }
        }

        public bool UpdateAgencyDiscount(Hashtable columns, string where)
        {
            //string sql = "update DISCOUNT set DISCOUNT=" + columns["DISCOUNT"].ToString() + where;
            if (database.Update("DISCOUNT",columns,where))
            {
                MessageBox.Show("更新代理商折扣信息成功！");
                return true;
            }
            else
            {
                MessageBox.Show("更新代理商折扣信息失败！");
                return false;
            }
        }

        public bool DeleteAgencyDiscount(string where)
        {
            if (database.Delete("DISCOUNT", where))
            {
                MessageBox.Show("删除物品成功！");
                return true;
            }
            else
            {
                MessageBox.Show("删除物品失败！");
                return false;
            }
        }
        #endregion
    }
}
